package com.cf.service.impl;

import com.cf.dao.ItemManDao;
import com.cf.entity.ItemMan;
import com.cf.service.ItemManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 59899
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ItemManServiceImpl implements ItemManService {

    @Autowired
    private ItemManDao itemManDao;

    @Override
    public int addItemMan(ItemMan itemMan) {
        return itemManDao.addItemMan(itemMan);
    }

    @Override
    public ItemMan selectItemByTel(String mtel) {
        return itemManDao.selectItemByTel(mtel);
    }

    @Override
    public int addItemManToItemMan(long iid, long mid) {
        Map map = new HashMap();
        map.put("iid",iid);
        map.put("mid",mid);
        return itemManDao.addItemManToItemMan(map);
    }

    @Override
    public int addOtherMessToItemMan(ItemMan itemMan, long iid) {
        Map map = new HashMap();
        map.put("inmoneynum", itemMan.getInmoneynum());
        map.put("statusnum",itemMan.getStatusnum());
        map.put("iid",iid);
        return itemManDao.addOtherMessToItemMan(map);
    }

    @Override
    public int deleteItemManAndManByIid(long iid) {
        //根据iid在中间表中查询mid
        long mid = itemManDao.selectMidByIid(iid);
        System.out.println(mid);
        //删除两个表中的信息
        int i1 = itemManDao.deleteItemManByMid(mid);
        int i2 = itemManDao.deleteItemManItemByIid(iid);
        if (i1!=0 && i2!=0){
            return 1;
        }else {
            return 0;
        }
    }

    @Override
    public ItemMan selectItemManByIid(long iid) {
        return itemManDao.selectItemManByIid(iid);
    }
}
